// 导入路由依赖
import { useRoutes } from "react-router-dom";
// 导入所需组件，首页  关于
import NoMatch from "../views/NoMatch";
import HomeView from "../views/HomeView";
import AboutView from "../views/AboutView";
import ProductView from "../views/ProductView";
import AdminView from "../views/admin/AdminView";
import DashView from "../views/admin/DashView";
import OrderList from "../views/admin/OrderList";

// 创建路由
const routes = [
    {
        path: "/",
        element: <HomeView></HomeView>
    },
    {
        path: "/about",
        element: <AboutView></AboutView>
    },
    {
        path: "/product/:id",
        element: <ProductView></ProductView>
    },
    {
        path: "/admin",
        element: <AdminView></AdminView>,
        // 配置子路由
        children: [
            {
                path: '',
                element: <DashView></DashView>
            },
            {
                path: 'orderlist',
                element: <OrderList></OrderList>
            },
        ]
    },
    // 配置404页面
    {
        path: "*",
        element: <NoMatch></NoMatch>
    }
]


// 使用useRoutes 创建
export default function RouterView() {
    // 创建路由
    const elem = useRoutes(routes);
    // 返回接口
    return elem
}